﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace SBPweb.RIA.Client.Controls.Windows
{

    public partial class MessageWindow : Window
    {

        public MessageWindow()
            : this("WindowsRootPanel")
        {

        }

        public MessageWindow(Canvas rootElement)
            : base(rootElement)
        {
            InitializeComponent();
            IsModal = true;
            ResizeMode = ResizeMode.NoResize;
            btnOk.Click += new RoutedEventHandler(btnOk_Click);
            btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
        }

        public MessageWindow(string rootElementName)
            : base(rootElementName)
        {
            InitializeComponent();
            IsModal = true;
            ResizeMode = ResizeMode.NoResize;
            btnOk.Click += new RoutedEventHandler(btnOk_Click);
            btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
        }

        public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(string), typeof(MessageWindow), null);
        public static readonly DependencyProperty BodyProperty = DependencyProperty.Register("Body", typeof(UIElement), typeof(MessageWindow), null);

        public string Header
        {
            get
            {
                return (string)GetValue(HeaderProperty);
            }
            set
            {
                SetValue(HeaderProperty, value);
                tbkHeader.Text = value;
            }
        }

        public UIElement Body
        {
            get
            {
                return GetValue(BodyProperty) as UIElement;
            }
            set
            {
                SetValue(BodyProperty, value);
                ccBody.Content = value;
            }
        }

        public bool HasOkButton
        {
            get
            {
                return btnOk.Visibility == System.Windows.Visibility.Visible;
            }
            set
            {
                btnOk.Visibility = value ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
            }
        }

        public bool HasCancelButton
        {
            get
            {
                return btnCancel.Visibility == System.Windows.Visibility.Visible;
            }
            set
            {
                btnCancel.Visibility = value ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
            }
        }

        #region Methods

        protected virtual void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            //this.Close();
        }

        protected virtual void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            //this.Close();
        }

        #endregion

    }

}